<div id="wrapper">
	<a target="_blank" id="photo" href="__MSG_module_url__"><span class="dummy">&nbsp;</span></a>
</div>
<style type="text/css">/*<!--*/
	body { margin:0; padding:0; color:#333; background:#fff; }
	#wrapper { padding:0; text-align:center; }
	#photo { width:240px; height:320px; margin:0 auto; display:block; position:relative; top:0; left:0; text-decoration:none; }
	.canvas #photo { width:590px; height:450px; margin:0; }
	/*#photo .dummy { display:block; width:100%; height:100%; z-index:9; position:absolute; top:0; left:0; }*/
    #photo .dummy { display:block; width:240px; height:320px; filter:alpha(opacity=0); -moz-opacity:0; opacity:0; background:#fff; z-index:9; position:absolute; top:0; left:0; cursor:pointer; }
	/*#photo img { position:absolute; top:0; left:0; width:100%; }*/
    #photo img,
    #photo span { position:absolute; top:0; left:0; width:100%; display:block; }
    img.hover { visibility:hidden; }
    .hover img { visibility:hidden; }
    .hover img.single,
    .hover img.hover { visibility:visible; }
	img { border:0; }
/*-->*/</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script type="text/javascript">/*<!--*/
;(function($){	// dom が使えるようになったら起動

var wrapper, photoDiv, currentPhoto;
var
	usedRandom = {},	// getRandom() を呼び出すことでランダムな 10桁の文字列が代入される
	defaultLink = "http://www.bijint.com/hokkaido/",
	isMixi = /^.+mixi\-platform.com$/.test(document.location.host);
var
	TIEUP_LINK2 = "http://www.jtb.co.jp/hokkaido/bijin/",
	TIEUP_LINK3 = "http://r.gnavi.co.jp/h247704/",
	TIEUP_LINK4 = "http://r.gnavi.co.jp/h247703/",
	TIEUP_LINK5 = "http://r.gnavi.co.jp/h247702/",
	TIEUP_LINK6 = "http://r.gnavi.co.jp/h255901/",
	TIEUP_LINK7 = "http://www.miraku-29.jp/",
	TIEUP_RE2 = /^(1500|1501|1502|1503|1504|1505|1506|1507|1508|1509|1510|1511|1512|1513|1514|1515|1516|1517|1518|1519|2300|2301|2302|2303|2304|2305|2306|2307|2308|2309|2310|2311|2312|2313|2314|2315|2316|2317|2318|2319|2320|2321|2322|2323|2324|2325|2326|2327|2328|2329|2330|2331|2332|2333|2334|2335|2336|2337|2338|2339|2340|2341|2342|2343|2344|2345|2346|2347|2348|2349|2350|2351|2352|2353|2354|2355|2356|2357|2358|2359)/,
	TIEUP_RE3 = /^(1600|1601|1602|1603)/,
	TIEUP_RE4 = /^(1604|1605|1606|1607)/,
	TIEUP_RE5 = /^(1608|1609|1610|1611)/,
	TIEUP_RE6 = /^(1612|1613|1614|1615)/,
	TIEUP_RE7 = /^(1616|1617|1618|1619|1620|1621|1622|1623)/,
	//TIEUP_HO = /^(9999|9999)/,
//	PHOTO_DOMAIN = "http://www.bijint.com",
	PHOTO_DOMAIN = "http://www.co-mind.info",
	/* Canvas 以外の画像へのパス */
	PHOTO_DIR = "240x320",
	/* Canvas 用画像へのパス */
	PHOTO_DIR_L = "590x450",
	PHOTO_EXT = ".jpg",
	DEFAULT_PHOTO_PATH = "/assets/pict/hokkaido/",
	/* TIEUP 時刻中に hover で表示する url */
	TIEUP_PHOTO_PATH = "/assets/pict/hokkaido-tieup/",
	RANDOM_BASE = "abcdefghijklmnopqrstuvwxyz0123456789",
//	PROXY_URL = "http://www.ig.gmodules.com/gadgets/proxy/refresh=3600&container=ig&gadget=http%3A%2F%2Fbijint.com%2Fgadget%2Fbinan%2FFgadget.xml/",
	PROXY_URL = "http://www.co-mind.info",
	RANDOM_LENGTH = 10,
	MAX_WIDTH = 240,
	MAX_HEIGHT = 320,
	MAX_WIDTH_L = 590,
	MAX_HEIGHT_L = 450,
	PADDING = 0,		// 実質定数
	MIXI_MAX_HEIGHT = 212;

/*
 * 美人時計のメインの処理
 */
function init() {
	wrapper =$("#wrapper");
	if(isCanvas()) {	// view が canvas の時の処理
		wrapper.addClass("canvas");
		MAX_WIDTH = MAX_WIDTH_L;
		MAX_HEIGHT = MAX_HEIGHT_L;
	}
	photoDiv = $("#photo");
	update(new Date());
	$(window).bind("resize",onResize);
	photoDiv.bind("mousedown",function(){
		sendTrack(true,true);	// google analytics に記録を残す
	});
	photoDiv.bind("click",function(){
		var href = $(this).attr("href");
		if(isMixi&&window.mixi&&mixi.util&&typeof mixi.util.requestExternalNavigateTo=="function") {
			setTimeout(function(){
				if(isCanvas())
					mixi.util.requestExternalNavigateTo(href);
				else
					gotoCanvas();
				return false;
			},99);
			return false;
		}
	});
    photoDiv.hover(function(){
        $(this).addClass("hover");
    },function(){
        $(this).removeClass("hover");
    });
	sendTrack();	// google analytics に記録を残す
	onResize();
}

function gotoCanvas() {	// view(canvas) に遷移する
	gadgets.views.requestNavigateTo(new gadgets.views.View("canvas"));
}


function sendTrack(time,click) {	// google analytics に記録を残す
	var path = "/gadget/binan/"+(isMixi?"mixi":"igoogle");
	var view = getView();
	if(view&&view!="home") path += "/"+view;
	if(time) path += "/"+time4Digits();
	if(click) path += "/click";
	try {
		_IG_Analytics("UA-11286402-1",path);
	} catch(e) {}
}

function getView() {	// 表示する view の type の名前を返す
	try {
		return gadgets.views.getCurrentView().getName().toLowerCase();
	} catch(e) { return ""; }
}

function isCanvas() {	// 表示する view が canvas なら true
	return /^canvas$/.test(getView());
}

function onResize() {	// onResize にバインド
	if(isMixi&&!isCanvas()) {	// mixi で Canvas 以外の処理
		photoDiv.css({
			width : Math.ceil(MAX_WIDTH*MIXI_MAX_HEIGHT/MAX_HEIGHT),
			height : MIXI_MAX_HEIGHT
		});
		gadgets.window.adjustHeight(MIXI_MAX_HEIGHT);
		return;
	}
	var w = $(window).width();
	var m = w<MAX_WIDTH+PADDING*2;
	photoDiv.css({	// 表示領域の CSS を再設定
		width : m?"100%":(MAX_WIDTH+"px"),
		height : m?"auto":(MAX_HEIGHT+"px")
	});
	defaultLink = defaultLink||photoDiv.attr("href");
	if(!currentPhoto) return;	// 写真を表示していなければ戻る
	setTimeout(function(){
		var h = currentPhoto.height()+PADDING*2||MAX_HEIGHT+PADDING*2;
		try {
			gadgets.window.adjustHeight(h);
		} catch(e) {
			try {
				_IG_AdjustIFrameHeight(h)
			} catch(e) {}
		}
	},0);
}

/*
 * 毎回異なる 10桁の文字列(a-z0-9からなり、重複する文字はない)を返す
 */
function getRandom() {
	do {
		var rnd = "";
		while(rnd.length<RANDOM_LENGTH) {
			rnd += RANDOM_BASE.charAt(Math.floor(Math.random()*RANDOM_BASE.length))||"";
		}
	} while(usedRandom[rnd]);
	usedRandom[rnd] = true;
	return rnd;
}

/*
 * タイアップ中の時刻なら true を返す
 * 　引数
 * 　date 現在時刻 hhmm
 * 　タイアップ時刻の正規表現
 */
function isTieup(date, tieup) {
	return tieup.test(time4Digits(date));
}

function update(date) {
	var timeout;
	var nextTime = new Date();
	nextTime = new Date(nextTime.getFullYear(),nextTime.getMonth(),nextTime.getDate(),nextTime.getHours(),nextTime.getMinutes()+1);
	if(date) {	// date に値があるのは最初に呼び出されたときだけ
		timeout = nextTime.getTime() - date.getTime();	// timeout = 次の正分
	} else {	// ２回目以降の呼び出しでは date に値がない
		date = nextTime;	// date = 次の正分
		timeout = 60000;	// timeout = 一分後
	}
	var fd = time4Digits(date);
	//var path = DEFAULT_PHOTO_PATH;
	//path += (isCanvas()?PHOTO_DIR_L:PHOTO_DIR)+"/"+fd+PHOTO_EXT;
	//if(!/^https?\:/.test(path)) path = PHOTO_DOMAIN+path;
	//var link = isTieup(date)?TIEUP_LINK:defaultLink;
	
	var link = defaultLink;
	if(isTieup(date,TIEUP_RE2)) link = TIEUP_LINK2;
	if(isTieup(date,TIEUP_RE3)) link = TIEUP_LINK3;
	if(isTieup(date,TIEUP_RE4)) link = TIEUP_LINK4;
	if(isTieup(date,TIEUP_RE5)) link = TIEUP_LINK5;
	if(isTieup(date,TIEUP_RE6)) link = TIEUP_LINK6;
	if(isTieup(date,TIEUP_RE7)) link = TIEUP_LINK7;
	
	var pict_path_hover;
	if(isTieup(date,TIEUP_RE2)) pict_path_hover = TIEUP_PHOTO_PATH;
	if(isTieup(date,TIEUP_RE3)) pict_path_hover = TIEUP_PHOTO_PATH;
	if(isTieup(date,TIEUP_RE4)) pict_path_hover = TIEUP_PHOTO_PATH;
	if(isTieup(date,TIEUP_RE5)) pict_path_hover = TIEUP_PHOTO_PATH;
	if(isTieup(date,TIEUP_RE6)) pict_path_hover = TIEUP_PHOTO_PATH;
	if(isTieup(date,TIEUP_RE7)) pict_path_hover = TIEUP_PHOTO_PATH;
	//var img = getImageURL(path);
	var id = "photo-"+getRandom();
	var loaded = false;
	/* 画像タグを含む <span> エレメントを作る */
	var ht = [
		"<span id=\"",id,"\" style=\"display:none;z-index:2;\">",
		getImageTag(DEFAULT_PHOTO_PATH,fd,"neutral"+(pict_path_hover?"":" single")),
		getImageTag(pict_path_hover,fd,"hover"),
		"</span>"
	];
	photoDiv.append($(ht.join("")));
	//photoDiv.append($([
	//	"<img src=\"",img,"\" id=\"",id,"\" style=\"display:none;z-index:2;\" />"
	//].join("")));
	var ele = $("#"+id);
	ele.data("link",link);
	setTimeout(function(){
		if(!loaded) update();	/* update() を再帰呼び出し */
	},timeout);
	$("img.neutral",ele).bind("load",function(){
	//ele.bind("load",function(){
		var d = new Date();
		var c = d.getTime();
		var t = date.getTime();
		var p = t-c;
		loaded = true;
		if(p<-60000) return ele.remove();
		if(p>0) {
			setTimeout(function(){ fadeIn(ele); },p);
			return;
		}
		fadeIn(ele);
	});
}

/*
 * 画像への img タグを返す
 * 　引数
 * 　　path 画像ファイルへのパス
 * 　　fd	画像ファイル名(拡張子なし)
 * 　　styleClass img タグの class アトリビュート
 */
function getImageTag(path,fd,styleClass) {
	if(!path) return "";		// path の指定がない場合は何もしないで戻る
	path += (isCanvas()?PHOTO_DIR_L:PHOTO_DIR)+"/"+fd+PHOTO_EXT;
	if(!/^https?\:/.test(path)) path = PHOTO_DOMAIN+path;
	var img = getImageURL(path);
	return "<img src=\""+img+"\" class=\""+styleClass+"\" />";
}

function fadeIn(ele) {
	ele.fadeIn();
	photoDiv.attr("href",ele.data("link"));
	if(currentPhoto) {
		currentPhoto.css("z-index","1");
		currentPhoto.fadeOut("slow",function(){
			$(this).remove();
		});
	}
	sendTrack(true);	// google analytics に記録を残す
	currentPhoto = ele;
	onResize();
	update();
}

/*  
 * n を二桁で返す
 */
function formatNum(n) {
	return n<10?"0"+n:String(n);
}

/*
 * 引数があればそれを、なければ今の時刻を hhmm の４桁で返す 
 */
function time4Digits(date) {
	date = date || new Date();
	return [
		formatNum(date.getHours()),
		formatNum(date.getMinutes())
	].join("");
}

function getImageURL(urlOrg) {
	if(urlOrg.indexOf("?")==-1) urlOrg += "?";
	var date = new Date();
/*	urlOrg += [
		"yyyymmdd=",
		date.getFullYear(),
		formatNum(date.getMonth()+1),
		formatNum(date.getDate()),
		"&ext=", PHOTO_EXT
	].join("");
*/	var url;
	try {
		url = gadgets.io.getProxyUrl(urlOrg);
	} catch(e) {
		try {
			url = _IG_GetImageUrl(urlOrg);
		} catch(e) {}
	}
	return url==urlOrg?PROXY_URL+urlOrg:url;
}

/*
 * dom 完成時にここからコードが走り出す
 */
try {
	gadgets.util.registerOnLoadHandler(init);
} catch(e) {
	try {
		_IG_RegisterOnloadHandler(init);	// for iGoole
	} catch(e) {
		$(init);
	}
}

/** start:MIXI AD PROGRAM */
(function(){
	if(!isMixi||!isCanvas()) return;
	var url = "http://mixi.jp/ad_application_program_invoker.pl?appli_id=10909&ad_id=1ed2aa6d5e08e5455c740676a0be1c47002b5906";
	document.writeln(['<scri','pt src="',url,'&ts=',(new Date).getTime(),'">','</scri','pt>'].join(''));
})();
/** end:MIXI AD PROGRAM */

})(jQuery.noConflict(true));

/*-->*/</script>
